** Replication File for "Financial Crisis and Democracy," International Organization 
** Phillip Y. Lipscy 


** Change this directory to the correct path on your computer:

cd "C:\Users\plipscy.POL-39M8VF2\Main Folder\Academic Projects\Financial Crisis Democracy\ReplicationFilesforIO\LipscyReplicationFiles\Analysis\"

** Preliminaries
** Note: see mergingdata.do in separate folder for dataset and variable construction
use "financialcrisisdemocracy.dta", clear

tsset ccode year

** Splines
btscs bcrises year ccode, g(peaceyears) lspline(1,4,7) failure


**
** Analysis
**

* Main Tables and Figures

* Figure 1: Time Spent in Banking Crisis (1800-2009), Various Measures of Democracy 

g dichopolity = 0 if polity2<=-7
replace dichopolity = 1 if polity2>=7
summarize stockdemocracy
g dichostock = 0 if stockdemocracy < ( -14.81589 - 81.47811)
replace dichostock = 1 if stockdemocracy > ( -14.81589 + 81.47811)

quietly logit bankingcrises boix_democracy
quietly eststo GRboix: margins, at(boix_democracy=(0 1)) post
quietly logit bankingcrises dichopolity
quietly eststo GRpolity: margins, at(dichopolity=(0 1)) post
quietly logit bankingcrises dichostock
quietly eststo GRstock: margins, at(dichostock=(0 1)) post

label define yesno 1 "Democracy" 0 "Autocracy"
label  values dichopolity yesno
label  values dichopolity yesno
label  values dichopolity yesno

coefplot (GRpolity, label(Polity)) (GRboix, label(Boix))  (GRstock, label(Stock)),  bylabel(dichopolity)  vertical  byopts(yrescale) xtitle("Democracy") ytitle("Time in Banking Crisis (Share of Country Years)") yscale(range(0 0.12)) ylabel(0(0.02)0.12) xlabel(`=1' "0" `=2' "1" ) legend(order(2 "Polity IV" 4 "Boix et al" 6 "Gerring et al") ring(0) position(4) bmargin(large)) 


* Figure 2: Financial Crisis and Democracy over Time

lowess boix_democracy year if bcrises==1, generate(lowone)
lowess boix_democracy year if bcrises==0, generate(lowzero)

preserve
collapse lowone, by(year)
rename lowone lowone_filled
save "temp.dta", replace
restore
merge m:1 year using "temp.dta", nogen

preserve
collapse lowzero, by(year)
rename lowzero lowzero_filled
save "temp.dta", replace
restore
merge m:1 year using "temp.dta", nogen

g lowdiff_filled = lowone_filled - lowzero_filled

twoway (line lowdiff_filled year if year <=1947) (line lowdiff_filled year if year >=1963, lpattern(solid)), xtitle("Year") ytitle("Share of Democracies (Crisis - Non Crisis)") legend(off)

* Text note about Fig 2 in 1900
summarize lowone_filled lowzero_filled lowdiff_filled if year == 1900


* Table 2 Financial Crisis and Democracy, 1800-2009 
* Note: observations are kept the same across models for the sake of BIC comparisons.  See Appendix IV for the same models using all available observations
logit bcrises polity2  _spline1 _spline2 _spline3 _prefail if  (ccode != 364 & ccode != 590  & ccode != 730) & !missing(gdppercap1000) & !missing(war) & !missing(currencycrises) & !missing(inflationcrises) & !missing(domesticdebtcrises) & !missing(externaldebtcrises)
estat ic
xtlogit bcrises polity2  _spline1 _spline2 _spline3 _prefail if   !missing(gdppercap1000) & !missing(war) & !missing(currencycrises) & !missing(inflationcrises) & !missing(domesticdebtcrises) & !missing(externaldebtcrises), fe
estat ic
xtlogit bcrises polity2 gdppercap1000 _spline1 _spline2 _spline3 _prefail if   !missing(war) & !missing(currencycrises) & !missing(inflationcrises) & !missing(domesticdebtcrises) & !missing(externaldebtcrises), fe
estat ic
xtlogit bcrises polity2  gdppercap1000 war currencycrises  _spline1 _spline2 _spline3 _prefail if   !missing(war) & !missing(currencycrises) & !missing(inflationcrises) & !missing(domesticdebtcrises) & !missing(externaldebtcrises), fe
estat ic
xtlogit bcrises polity2  gdppercap1000 war currencycrises inflationcrises domesticdebtcrises externaldebtcrises  _spline1 _spline2 _spline3 _prefail if   !missing(war) & !missing(currencycrises) & !missing(inflationcrises) & !missing(domesticdebtcrises) & !missing(externaldebtcrises), fe
estat ic


* Table 3 Financial Crisis and Alternative Measures and Relationships with Democracy, 1800-2009 
xtlogit bcrises polity2  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if  !missing(polity2)  , fe
estat ic
xtlogit bcrises polity2 newdemocracy5 gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if  !missing(polity2)  , fe
estat ic
xtlogit bcrises polity2 undstabledemocracydicho gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if  !missing(polity2)  , fe
estat ic
xtlogit bcrises consdem transdem gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if  !missing(polity2)  , fe
estat ic
xtlogit bcrises boix_democracy  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if  !missing(polity2)  , fe
estat ic
xtlogit bcrises stockdemocracy gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if  !missing(polity2)  , fe
estat ic


* Table 4 Financial Crisis and Democracy, Various Time Periods of Interest
xtlogit bcrises polity2  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if year < 1901, fe
estat ic
xtlogit bcrises polity2  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if year >= 1900 & year < 2001, fe
estat ic
xtlogit bcrises polity2  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if year >= 1945, fe
estat ic
xtlogit bcrises polity2  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if year >= 1971, fe
estat ic
xtlogit bcrises polity2  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if year >= 1980 & year <=2000, fe
estat ic


* Figure 3: Regime Type and Contagion  

egen propcrisisall = mean(bcrises), by(year)
egen propcrisisdem = mean(bcrises) if boix_democracy == 1, by(year)
egen propcrisisaut = mean(bcrises) if boix_democracy == 0, by(year)

twoway (lowess propcrisisdem propcrisisall) (lowess propcrisisaut propcrisisall) (scatter propcrisisdem propcrisisall, msymbol(o)) (scatter propcrisisaut propcrisisall, msymbol(X)), legend(order(3 "Democracies" 4 "Autocracies") ring(0) position(2) bmargin(large)) xtitle("Share of All Countries in Banking Crises") ytitle("Share of Countries in Banking Crises" "by Regime Type")



* Table 6 Considering the Hypotheses 
xtlogit bcrises polity2  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if !missing(henisz_polconiii) & !missing(turnover) & !missing(finlib) & !missing(log_scaled_barbieri) , fe
estat ic
xtlogit bcrises polity2 henisz_polconiii turnover finlib log_scaled_barbieri  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail, fe
estat ic
xtlogit bcrises polity2 gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if !missing(henisz_polconiii) & !missing(turnover) & !missing(log_scaled_barbieri), fe
estat ic
xtlogit bcrises polity2 henisz_polconiii turnover  log_scaled_barbieri gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail, fe
estat ic



** 
** Appendix Tables and Figures (other empirical claims in main text and footnotes included separately below)
** 


* Appendix Table A1 Financial Crisis and Democracy, Lagged Democracy as the Independent Variable

xtlogit bcrises lpolity1  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail, fe
estat ic
xtlogit bcrises lpolity5  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail, fe
estat ic
xtlogit bcrises lpolity10  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail, fe
estat ic

* Table A2 Financial Crisis and Democracy, Rare Events Logit

relogit bcrises polity2  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail

* Table A3 Financial Crisis and Democracy, Excluding USA, UK, Netherlands
xtlogit bcrises polity2 gdppercap1000 currencycrises war    _spline1 _spline2 _spline3 _prefail if scode !="USA" & scode !="UKG" & scode !="NTH", fe
estat ic


* Table A4: Financial Crisis and Democracy, Onset of All Crisis Types

g allcrises = bcrises
replace allcrises = 1 if currencycrises == 1 | inflationcrises == 1 | domesticdebtcrises == 1 | externaldebtcrises == 1 
drop _frstfl  _prefail  _tuntilf _spline1 _spline2 _spline3 peaceyears
btscs allcrises year ccode, g(peaceyears) lspline(1,4,7) failure
bysort ccode: replace allcrises = . if allcrises[_n-1] == 1 
xtlogit allcrises polity2 gdppercap1000 war _spline1 _spline2 _spline3 _prefail , fe
estat ic

drop _frstfl  _prefail  _tuntilf _spline1 _spline2 _spline3 peaceyears
btscs bcrises year ccode, g(peaceyears) lspline(1,4,7) failure



* Table A5: Financial Crisis and Democracy (Considering Financial Sector Size) 

xtlogit bcrises polity2  gdppercap1000 war currencycrises  _spline1 _spline2 _spline3 _prefail if ccode != 371 &  ccode != 373 &  ccode != 370 &  ccode != 366 &  ccode != 372 &  ccode != 705 &  ccode != 703 &  ccode != 367 &  ccode != 368 &  ccode != 359 &  ccode != 365 &  ccode != 701 &  ccode != 702 &  ccode != 704 &  ccode != 369 &  ccode != 310 &  ccode != 315 &  ccode != 290 &  ccode != 360 &  ccode != 265 &  ccode != 355 &  ccode != 345 &  ccode != 339 &  ccode != 40 &  ccode != 55 &  ccode != 434 &  ccode != 540 &  ccode != 541 &  ccode != 530 &  ccode != 520 &  ccode != 680 &  ccode != 700 &  ccode != 712 &  ccode != 710 &  ccode != 731 &  ccode != 816 &  ccode != 811 &  ccode != 812, fe
estat ic
xtlogit bcrises polity2  gdppercap1000 war currencycrises  _spline1 _spline2 _spline3 _prefail if newprivatecredit > 5 & !missing(newprivatecredit), fe
estat ic
xtlogit bcrises polity2  gdppercap1000 war currencycrises newprivatecredit _spline1 _spline2 _spline3 _prefail , fe
estat ic


* Table A6: Financial Crisis and Democracy, 1800-2009 (Including Political Constraints) 

xtlogit bcrises  polity2  gdppercap1000 currencycrises war    _spline1 _spline2 _spline3 _prefail if !missing(henisz_polconiii), fe
estat ic
xtlogit bcrises polity2 henisz_polconiii   gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail, fe
estat ic
xtlogit bcrises  polity2 l5constraintsstock gdppercap1000 currencycrises war    _spline1 _spline2 _spline3 _prefail , fe
estat ic


* Table A7: Financial Crisis and Democracy, 1800-2009 (Several Alternative Measures of Time Horizons)


xtlogit bcrises polity2  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if !missing(turnover) & !missing(age) & !missing(lnsumten) & turnover_cum !=0, fe
estat ic
xtlogit bcrises polity2 turnover  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if !missing(turnover) & !missing(age) & !missing(lnsumten) & turnover_cum !=0, fe
estat ic
xtlogit bcrises polity2 age  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if !missing(turnover) & !missing(age) & !missing(lnsumten) & turnover_cum !=0, fe
estat ic
xtlogit bcrises polity2 lnsumten  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if !missing(turnover) & !missing(age) & !missing(lnsumten) & turnover_cum !=0, fe
estat ic
xtlogit bcrises polity2  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if !missing(partyturnover), fe
estat ic
xtlogit bcrises polity2 partyturnover gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail, fe
estat ic



* Appendix II

* Figure AII1
twoway (lowess finlib year if boix_democracy ==1 & year >= 1970) (lowess finlib year if boix_democracy ==0 & year >= 1970) , legend(order(1 "Democracy" 2 "Autocracy") ring(0) position(10) bmargin(large)) xtitle("Year") ytitle("Financial Liberalization Index")

* Table AII1: Correlation Table, Democracy and Capital Controls
bysort ccode (year): g dcapcont = capcont - capcont[_n-1]
bysort ccode (year): g d5capcont = capcont - capcont[_n-5]
bysort ccode (year): g d10capcont = capcont - capcont[_n-10]

cor dcapcont dpolity2 if year >= 1880 & year <= 1945
cor d5capcont d5polity2 if year >= 1880 & year <= 1945
cor d10capcont d10polity2 if year >= 1880 & year <= 1945

cor dcapcont dpolity2 if year >= 1945 & year <= 1980
cor d5capcont d5polity2 if year >= 1945 & year <= 1980
cor d10capcont d10polity2 if year >= 1945 & year <= 1980

cor dcapcont dpolity2 if year >= 1980 & year <= 2000
cor d5capcont d5polity2 if year >= 1980 & year <= 2000
cor d10capcont d10polity2 if year >= 1980 & year <= 2000

*Table AII2: Capital Controls and Democracy  
xtlogit capcont polity2 if year >= 1880 & year <= 1945, fe
xtlogit capcont polity2 if year >= 1945 & year <= 1980, fe
xtlogit capcont polity2 if year >= 1980 & year <= 2000, fe


* Appendix III: Supplemental Analysis Concerning Contagion 

xtlogit bcrises polity2  gdppercap1000 currencycrises war _spline1 _spline2 _spline3 _prefail if year!=1890 & year!=1907 & year!=1914 & year!=1921 & year!=1923 & year!=1931 & (year < 1990 | year > 1992) & year!=1994 & year!=1995 & year!=1997 & year!=2008, fe
estat ic
xtlogit bcrises polity2  dum1890 dum1900 dum1910 dum1920 dum1930 dum1990 dum2000 gdppercap1000 currencycrises war    _spline1 _spline2 _spline3 _prefail , fe
estat ic
xtlogit bcrises polity2  ave_polity2 gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail, fe
estat ic


* Appendix IV: Replication of Table 2 Including All Available Observations
logit bcrises polity2  _spline1 _spline2 _spline3 _prefail 
estat ic
xtlogit bcrises polity2 _spline1 _spline2 _spline3 _prefail , fe
estat ic
xtlogit bcrises polity2 gdppercap1000 _spline1 _spline2 _spline3 _prefail , fe
estat ic
xtlogit bcrises polity2  gdppercap1000 war currencycrises  _spline1 _spline2 _spline3 _prefail , fe
estat ic
xtlogit bcrises polity2  gdppercap1000 war currencycrises inflationcrises domesticdebtcrises externaldebtcrises  _spline1 _spline2 _spline3 _prefail , fe
estat ic


* Appendix V: Supplemental Raw Data Presentations Using Alternative Measures of Democracy


* Figure AV1: Financial Crisis and Democracy (Polity)
twoway lowess bankingcrises polity2, xtitle("Democracy Score (Polity2)") ytitle("Banking Crisis (Share of Country Years)") legend(off)


* Figure AV2: Financial Crisis and Democracy (Democracy as a Stock)
twoway lowess bankingcrises stockdemocracy, xtitle("Democracy Stock") ytitle("Banking Crisis (Share of Country Years)") legend(off)

* Figure AV3: Financial Crisis and Democracy over Time with Polity Scores
lowess polity2 year if bcrises==1, generate(lowonepolity)
lowess polity2 year if bcrises==0, generate(lowzeropolity)

preserve
collapse lowonepolity, by(year)
rename lowonepolity lowonepolity_filled
save "temp.dta", replace
restore
merge m:1 year using "temp.dta", nogen

preserve
collapse lowzeropolity, by(year)
rename lowzeropolity lowzeropolity_filled
save "temp.dta", replace
restore
merge m:1 year using "temp.dta", nogen

g lowdiffpolity_filled = lowonepolity_filled - lowzeropolity_filled

twoway (line lowdiffpolity_filled year if year <=1947) (line lowdiffpolity_filled year if year >=1963, lpattern(solid)), xtitle("Year") ytitle("Difference in Polity Score (Crisis - Non Crisis)") legend(off)


* Figure AV4: Financial Crisis and Democracy over Time with Democracy Stock
lowess stockdemocracy year if bcrises==1, generate(lowonestock)
lowess stockdemocracy year if bcrises==0, generate(lowzerostock)

preserve
collapse lowonestock, by(year)
rename lowonestock lowonestock_filled
save "temp.dta", replace
restore
merge m:1 year using "temp.dta", nogen

preserve
collapse lowzerostock, by(year)
rename lowzerostock lowzerostock_filled
save "temp.dta", replace
restore
merge m:1 year using "temp.dta", nogen

g lowdiffstock_filled = lowonestock_filled - lowzerostock_filled

twoway (line lowdiffstock_filled year if year <=1947) (line lowdiffstock_filled year if year >=1963, lpattern(solid)), xtitle("Year") ytitle("Difference in Democratic Stock (Crisis - Non Crisis)") legend(off)



* Appendix VI: Additional Hypotheses Related to Constraints

* There is some evidence of a weak negative association between polity2 and real rates, but real rates are not negatively associated with banking crisis onset
bysort ccode (year): g inflationrate =  100 * (cpi - cpi[_n-1])/cpi[_n-1]
g rstir = stir - inflationrate
g rltrate = ltrate - inflationrate 

xtreg rstir polity2, fe
xtreg rltrate polity2, fe

xtlogit bcrises rstir gdppercap1000 war currencycrises _spline1 _spline2 _spline3 _prefail , fe
xtlogit bcrises ltrate gdppercap1000 war currencycrises _spline1 _spline2 _spline3 _prefail , fe

* Constraint stock variable without lag  
xtlogit bcrises polity2 constraintsstock gdppercap1000 currencycrises war _spline1 _spline2 _spline3 _prefail , fe
estat ic





** 
** Empirical Claims in Footnotes and Text
** 

* Footnote 17 about GDP growth rates during depression years
bysort ccode (year): g pct6gdppercap1000 = (gdppercap1000 - gdppercap1000[_n-6])/gdppercap1000[_n-6]
mean pct6gdppercap1000 if year == 1935 & (ccode == 2 | ccode == 220 | ccode == 200)
list pct6gdppercap1000 if year == 1935 & (ccode == 740)
list pct6gdppercap1000 if year == 1935 & (ccode == 364)  

* Footnote 20 about France
list country ccode year bankingcrises if bankingcrises == 1 & country == "France"
summarize bankingcrises polity2 if country == "France" & year <= 1870
summarize bankingcrises polity2 if country == "France" & year >= 1871 &  year <= 1939

* Footnote 21 about Japan
summarize bankingcrises if country == "Japan" & year >= 1914 &  year <= 1931
summarize bankingcrises if country == "Japan" & year >= 1929 &  year <= 1945

* Footnote 33 about coding ongoing banking crises as 0 instead of missing
logit bcrises polity2  _spline1 _spline2 _spline3 _prefail 
xtlogit bcrises polity2  gdppercap1000 war currencycrises  _spline1 _spline2 _spline3 _prefail, fe

g bcrises2 = 0 if bankingcrises == 1 | bankingcrises ==0
bysort ccode: replace bcrises2 = 1 if bankingcrises[_n] - bankingcrises[_n-1] == 1
replace bcrises2 = 1 if ccode == 750 & year == 1947
drop _frstfl  _prefail  _tuntilf _spline1 _spline2 _spline3 peaceyears
btscs bcrises2 year ccode, g(peaceyears) lspline(1,4,7) failure

logit bcrises2 polity2  _spline1 _spline2 _spline3 _prefail 
xtlogit bcrises2 polity2  gdppercap1000 war currencycrises  _spline1 _spline2 _spline3 _prefail, fe

drop _frstfl  _prefail  _tuntilf _spline1 _spline2 _spline3 peaceyears
btscs bcrises year ccode, g(peaceyears) lspline(1,4,7) failure

* Footnote 35 Several examples of alternative knot placements
drop _frstfl  _prefail  _tuntilf _spline1 _spline2 _spline3 peaceyears
btscs bcrises year ccode, g(peaceyears) nspline(3) failure
logit bcrises polity2  _spline1 _spline2 _spline3 _prefail 
xtlogit bcrises polity2  gdppercap1000 war currencycrises  _spline1 _spline2 _spline3 _prefail, fe

drop _frstfl  _prefail  _tuntilf _spline1 _spline2 _spline3 peaceyears
btscs bcrises year ccode, g(peaceyears) lspline(1, 5, 10) failure
logit bcrises polity2  _spline1 _spline2 _spline3 _prefail 
xtlogit bcrises polity2  gdppercap1000 war currencycrises  _spline1 _spline2 _spline3 _prefail, fe

drop _frstfl  _prefail  _tuntilf _spline1 _spline2 _spline3 peaceyears
btscs bcrises year ccode, g(peaceyears) lspline(1, 10, 20) failure
logit bcrises polity2  _spline1 _spline2 _spline3 _prefail 
xtlogit bcrises polity2  gdppercap1000 war currencycrises  _spline1 _spline2 _spline3 _prefail, fe

drop _frstfl  _prefail  _tuntilf _spline1 _spline2 _spline3 peaceyears
btscs bcrises year ccode, g(peaceyears) lspline(1,4,7) failure

* Footnote 45 additional BIC comparisons show including crisis types aside from currency crises do not improve model fit.  

xtlogit bcrises polity2 gdppercap1000 war currencycrises  _spline1 _spline2 _spline3 _prefail if   !missing(war) & !missing(currencycrises) & !missing(inflationcrises) & !missing(domesticdebtcrises) & !missing(externaldebtcrises), fe
estat ic
xtlogit bcrises polity2 gdppercap1000 war currencycrises inflationcrises  _spline1 _spline2 _spline3 _prefail if   !missing(war) & !missing(currencycrises) & !missing(inflationcrises) & !missing(domesticdebtcrises) & !missing(externaldebtcrises), fe
estat ic
xtlogit bcrises polity2 gdppercap1000 war currencycrises domesticdebtcrises  _spline1 _spline2 _spline3 _prefail if   !missing(war) & !missing(currencycrises) & !missing(inflationcrises) & !missing(domesticdebtcrises) & !missing(externaldebtcrises), fe
estat ic
xtlogit bcrises polity2 gdppercap1000 war currencycrises externaldebtcrises  _spline1 _spline2 _spline3 _prefail if   !missing(war) & !missing(currencycrises) & !missing(inflationcrises) & !missing(domesticdebtcrises) & !missing(externaldebtcrises), fe
estat ic

xtlogit bcrises polity2  gdppercap1000 war currencycrises  _spline1 _spline2 _spline3 _prefail if   !missing(war) & !missing(currencycrises) & !missing(inflationcrises) & !missing(domesticdebtcrises) & !missing(externaldebtcrises), fe
estat ic
xtlogit bcrises  gdppercap1000 war currencycrises  _spline1 _spline2 _spline3 _prefail if  !missing(polity2) &  !missing(war) & !missing(currencycrises) & !missing(inflationcrises) & !missing(domesticdebtcrises) & !missing(externaldebtcrises), fe
estat ic
  

* Footnote 46 examples of alternative cutoffs for new and unstable democracy show similar results

g newdemocracy1 = 0
replace newdemocracy1 = 1 if polity2 > 0 & lpolity10 < 0
g newdemocracy2 = 0
replace newdemocracy2 = 1 if polity2 > 6 & lpolity5 < 7
g newdemocracy3 = 0
replace newdemocracy3 = 1 if polity2 > 0 & lpolity5 < 0

xtlogit bcrises polity2 newdemocracy1 gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail , fe
xtlogit bcrises polity2 newdemocracy2 gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail , fe
xtlogit bcrises polity2 newdemocracy3 gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail , fe

g undstabledemocracydicho2 = 0
replace undstabledemocracydicho2 = 1 if d20polity2 != 0
g undstabledemocracydicho3 = 0
replace undstabledemocracydicho3 = 1 if d5polity2 != 0
g undstabledemocracydicho4 = 0
replace undstabledemocracydicho4 = 1 if dpolity2 != 0

xtlogit bcrises polity2 undstabledemocracydicho2 gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail , fe
xtlogit bcrises polity2 undstabledemocracydicho3 gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail , fe
xtlogit bcrises polity2 undstabledemocracydicho4 gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail , fe
  
* Footnote 48 square of polity2 is not meaningfully associated with banking crises 

g adjpolity2 = polity2 + 10
g adjpolity2_sq = adjpolity2^2
xtlogit bcrises adjpolity2 adjpolity2_sq gdppercap1000 currencycrises war  _spline1 _spline2 _spline3 _prefail  , fe  
  
* Footnote 49 dichotomous democracy measure derived from polity2 

xtlogit bcrises dichopolity gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail  , fe  

* Footnote 50 democracy stock measure not significant for low depreciation rates (<2%) but significant for higher depreciation rates

g stockdemocracyx1 = .
g incstockdemx1 = .
g cumstockdemx1 = .

foreach i of num 1800/2009 {
	bysort ccode (year): replace incstockdemx1 = (polity2*0.99^(-(year-`i')))
	bysort ccode: replace cumstockdemx1 = sum(incstockdemx1)
	bysort ccode: replace stockdemocracyx1 = cumstockdemx1 if year ==`i'
}

xtlogit bcrises stockdemocracyx1 gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if  !missing(polity2)  , fe

g stockdemocracyx2 = .
g incstockdemx2 = .
g cumstockdemx2 = .

foreach i of num 1800/2009 {
	bysort ccode (year): replace incstockdemx2 = (polity2*0.98^(-(year-`i')))
	bysort ccode: replace cumstockdemx2 = sum(incstockdemx2)
	bysort ccode: replace stockdemocracyx2 = cumstockdemx2 if year ==`i'
}

xtlogit bcrises stockdemocracyx2 gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if  !missing(polity2)  , fe

g stockdemocracyx10 = .
g incstockdemx10 = .
g cumstockdemx10 = .

foreach i of num 1800/2009 {
	bysort ccode (year): replace incstockdemx10 = (polity2*0.90^(-(year-`i')))
	bysort ccode: replace cumstockdemx10 = sum(incstockdemx10)
	bysort ccode: replace stockdemocracyx10 = cumstockdemx10 if year ==`i'
}

xtlogit bcrises stockdemocracyx10 gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if  !missing(polity2)  , fe

* Footnote 57 Alternative Time Periods

* WWI split also works
xtlogit bcrises polity2  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if year < 1914, fe
xtlogit bcrises polity2  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if year >= 1914, fe

* As noted in text, very short time periods & periods dominated by 1945-1975 do not work
xtlogit bcrises polity2  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if year >= 1918 & year <=1939, fe
xtlogit bcrises polity2  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if year >= 2000 & year <=2009, fe
xtlogit bcrises polity2  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if year >= 1945 & year <=1990, fe


* Footnote 78, Japan's POLCONIII score in 1989
summarize henisz_polconiii if country == "Japan" & year == 1989
summarize henisz_polconiii if year == 1989, detail

* Footnote 80, Sweden's POLCONIII score in 1922
summarize henisz_polconiii if country == "Sweden" & year == 1922
summarize henisz_polconiii if year == 1922, detail

* Turnover subection paragraph 1, tenure of democratic and autocratic leaders
mean sumten if polity2 <= -7
mean sumten if polity2 >= 7

* Turnover subsection paragraph 3, association of turnover with regime type and time remaining in office
cor turnover polity2 time_remaining

* Liberalization subsection para 5, correlation between liberalization and capital openness 
cor intlcapital finlib

* footnote 107, list of years where banking crisis onset is more than 10% of countries 
list propcrisisall year if ccode ==2 &  propcrisisall > 0.1

* footnote 114, Eichengreen Leblang 2008 capital control measure is not meaningfully associated with banking crisis onset
xtlogit bcrises polity2 capcont gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail, fe
xtlogit bcrises polity2 capcont henisz_polconiii turnover log_scaled_barbieri  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail, fe


* footnote 115, substituting Boix and Gerring measures of democracy in Table 6 anaylsis
xtlogit bcrises boix_democracy  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if !missing(henisz_polconiii) & !missing(turnover) & !missing(finlib) & !missing(log_scaled_barbieri) , fe
estat ic
xtlogit bcrises boix_democracy henisz_polconiii turnover finlib log_scaled_barbieri  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail, fe
estat ic
xtlogit bcrises boix_democracy gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if !missing(henisz_polconiii) & !missing(turnover) & !missing(log_scaled_barbieri), fe
estat ic
xtlogit bcrises boix_democracy henisz_polconiii turnover  log_scaled_barbieri gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail, fe
estat ic

xtlogit bcrises stockdemocracy  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if !missing(henisz_polconiii) & !missing(turnover) & !missing(finlib) & !missing(log_scaled_barbieri) , fe
estat ic
xtlogit bcrises stockdemocracy henisz_polconiii turnover finlib log_scaled_barbieri  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail, fe
estat ic
xtlogit bcrises stockdemocracy gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if !missing(henisz_polconiii) & !missing(turnover) & !missing(log_scaled_barbieri), fe
estat ic
xtlogit bcrises stockdemocracy henisz_polconiii turnover  log_scaled_barbieri gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail, fe
estat ic

* Analysis section para 3, turnover is not associated with banking crisis onset in 1973-2005 avilable observations
xtlogit bcrises polity2 turnover gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if !missing(henisz_polconiii) & !missing(turnover) & !missing(finlib) & !missing(log_scaled_barbieri) , fe


* footnote 116, BIC comparisons including and omitting democracy after including mechanism variables; per Raftery 1995, BIC difference in excess of 6 is considered "strong" evidence in favor of a model
xtlogit bcrises polity2 henisz_polconiii turnover finlib log_scaled_barbieri  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail, fe
estat ic
xtlogit bcrises henisz_polconiii turnover finlib log_scaled_barbieri  gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if !missing(polity2), fe
estat ic
xtlogit bcrises polity2 henisz_polconiii turnover  log_scaled_barbieri gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail, fe
estat ic
xtlogit bcrises henisz_polconiii turnover  log_scaled_barbieri gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if !missing(polity2), fe
estat ic

* footnote 116, BIC comparisons including mechanism variables one by one
xtlogit bcrises polity2 gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if !missing(henisz_polconiii) & !missing(turnover) & !missing(finlib) & !missing(log_scaled_barbieri) , fe
estat ic
xtlogit bcrises polity2 henisz_polconiii gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if !missing(henisz_polconiii) & !missing(turnover) & !missing(finlib) & !missing(log_scaled_barbieri) , fe
estat ic
xtlogit bcrises polity2 henisz_polconiii turnover gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if !missing(henisz_polconiii) & !missing(turnover) & !missing(finlib) & !missing(log_scaled_barbieri) , fe
estat ic
xtlogit bcrises polity2 henisz_polconiii turnover finlib gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if !missing(henisz_polconiii) & !missing(turnover) & !missing(finlib) & !missing(log_scaled_barbieri) , fe
estat ic
xtlogit bcrises polity2 henisz_polconiii turnover finlib log_scaled_barbieri gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if !missing(henisz_polconiii) & !missing(turnover) & !missing(finlib) & !missing(log_scaled_barbieri) , fe
estat ic

xtlogit bcrises polity2 gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if !missing(henisz_polconiii) & !missing(turnover) & !missing(log_scaled_barbieri) , fe
estat ic
xtlogit bcrises polity2 henisz_polconiii gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if !missing(henisz_polconiii) & !missing(turnover) & !missing(log_scaled_barbieri) , fe
estat ic
xtlogit bcrises polity2 henisz_polconiii turnover gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if !missing(henisz_polconiii) & !missing(turnover) & !missing(log_scaled_barbieri) , fe
estat ic
xtlogit bcrises polity2 henisz_polconiii turnover log_scaled_barbieri gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if !missing(henisz_polconiii) & !missing(turnover) & !missing(log_scaled_barbieri) , fe
estat ic

* footnote 116, omitting turnover produces similar results
xtlogit bcrises polity2 henisz_polconiii finlib log_scaled_barbieri gdppercap1000 currencycrises war   _spline1 _spline2 _spline3 _prefail if !missing(henisz_polconiii) & !missing(turnover) & !missing(log_scaled_barbieri) , fe


* Footnote 117 and related text: No autocracies score high on all four mechanism variables 

preserve
collapse (mean) finlib if bcrises == 1 | bcrises == 0, by(year)
rename finlib ave_finlib
save "temp.dta", replace
restore
merge m:1 year using "temp.dta", nogen

preserve
collapse (mean) t_weight_barbieri if bcrises == 1 | bcrises == 0, by(year)
rename t_weight_barbieri ave_t_weight_barbieri
save "temp.dta", replace
restore
merge m:1 year using "temp.dta", nogen

preserve
collapse (mean) turnover if bcrises == 1 | bcrises == 0, by(year)
rename turnover ave_turnover
save "temp.dta", replace
restore
merge m:1 year using "temp.dta", nogen

preserve
collapse (mean) henisz_polconiii if bcrises == 1 | bcrises == 0, by(year)
rename henisz_polconiii ave_henisz_polconiii
save "temp.dta", replace
restore
merge m:1 year using "temp.dta", nogen

list country year if polity2 < -6 & henisz_polconiii > ave_henisz_polconiii & turnover > ave_turnover & t_weight_barbieri > ave_t_weight_barbieri & finlib > ave_finlib & !missing(bankingcrises)
list country year if polity2 < 0 & henisz_polconiii > ave_henisz_polconiii & turnover > ave_turnover & t_weight_barbieri > ave_t_weight_barbieri & finlib > ave_finlib & !missing(bankingcrises)






